from django.shortcuts import render
from django.http import JsonResponse,HttpResponse,HttpRequest
from .service.demo_user_service import DemoUserService
from rest_framework.decorators import api_view
from django.forms.models import model_to_dict
# from django.core import serializers # 序列化
from utils.serializer import serialize

# Create your views here.
@api_view(['POST'])
def reg(requer:HttpRequest):
    return HttpResponse("test")

@api_view(['GET'])
def get_user_by_id(requer:HttpRequest):
    user_service = DemoUserService()
    data = user_service.get_user_by_id(1)
    jsonData = serialize.to_dict(data)
    return JsonResponse({'status': 'success', 'data': jsonData})